package me.monster.smarttraffic.ui.info;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import me.monster.smarttraffic.R;
import me.monster.smarttraffic.SplashActivity;
import me.monster.smarttraffic.base.AbstractPresenterActivity;
import me.monster.smarttraffic.bo.DataHolder;
import me.monster.smarttraffic.tool.ImageLoader;
import me.monster.smarttraffic.tool.Util;

/**
 * @description
 * @author: Created jiangjiwei in 2020-02-15 19:49
 */
public class InfoActivity extends AbstractPresenterActivity<InfoPresenter> implements InfoContract.View {

    @BindView(R.id.iv_info_avatar)
    ImageView ivAvatar;
    @BindView(R.id.tv_info_quote)
    TextView tvQuote;
    @BindView(R.id.tv_info_account)
    TextView tvAccount;

    public static void start(Activity context) {
        Intent starter = new Intent(context, InfoActivity.class);
        context.startActivity(starter);
        context.overridePendingTransition(R.anim.scale_alpha_rotate_in, R.anim.alpha_out);
    }

    @OnClick(R.id.btn_info_logout)
    public void onLogout() {
        mPresenter.clearAuth();
        SplashActivity.start(this);
        for (Activity activity : Util.getActivityList()) {
            activity.finish();
        }
    }

    @Override
    public InfoPresenter createPresenter() {
        return new InfoPresenter();
    }

    @Override
    public View closeToolView() {
        return findViewById(R.id.tv_info_avatar);
    }

    @Override
    public String getInitTitle() {
        return getString(R.string.dash_menu_i);
    }

    @Override
    protected void onResume() {
        super.onResume();
        final DataHolder instance = DataHolder.getInstance();
        tvAccount.setText(instance.getAccount());
        tvQuote.setText(instance.getQuote());
        ImageLoader.loadAvatar(instance.getAvatar(), ivAvatar);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_info;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void dismissLoading() {

    }

    @Override
    public void showError(int error) {

    }
}
